<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Page Info->Info
 * Overview to the System.
 *
 * @version    $Id$
 * @package    TobbiVM-Shop
 * @copyright  Copyright (C) 2012
 * @author     Norbert Gebert
 * @license    GPL3
 */
function contentPage($refPage, $page, $subpage, $refValidate)
{
	$refPage->assign('header', _('Shop Overview page'));

	// Categorys
	$refPage->assign('activeCategoryText', _('Active categories') . ' :');
	$result = db::getInstance()->rawQuery(
		"SELECT COUNT(*) as value FROM category WHERE category_active = '1'");
	$refPage->assign('activeCategoryValue', $result[0]['value']);

	$refPage->assign('disabledCategoryText', _('Disabled categories') . ' :');
	$result = db::getInstance()->rawQuery(
		"SELECT COUNT(*) as value FROM category WHERE category_active = '0'");
	$refPage->assign('disabledCategoryValue', $result[0]['value']);

	// Article
	$refPage->assign('activeArticleText', _('Active article') . ' :');
	$result = db::getInstance()->rawQuery(
		"SELECT COUNT(*) as value FROM product WHERE product_active = '1'");
	$refPage->assign('activeArticleValue', $result[0]['value']);

	$refPage->assign('disabledArticleText', _('Disabled article') . ' :');
	$result = db::getInstance()->rawQuery(
		"SELECT COUNT(*) as value FROM product WHERE product_active = '0'");
	$refPage->assign('disabledArticleValue', $result[0]['value']);

	// Customer
	$refPage->assign('activeCustomerText', _('Active customer') . ' :');
	$result = db::getInstance()->rawQuery(
		"SELECT COUNT(*) as value FROM customer WHERE customer_active = '1'");
	$refPage->assign('activeCustomerValue', $result[0]['value']);

	$refPage->assign('disabledCustomerText', _('Disabled customer') . ' :');
	$result = db::getInstance()->rawQuery(
		"SELECT COUNT(*) as value FROM customer WHERE customer_active = '0'");
	$refPage->assign('disabledCustomerValue', $result[0]['value']);

	// Orderer
	$refPage->assign('ordererText', _('Registered orderer') . ' :');
	$result = db::getInstance()->rawQuery(
		"SELECT COUNT(*) as value FROM orderer");
	$refPage->assign('ordererValue', $result[0]['value']);

	// Orders
	$refPage->assign('ordersText', _('Occurred orders') . ' :');
	$result = db::getInstance()->rawQuery(
		"SELECT COUNT(*) as value FROM ordered");
	$refPage->assign('ordersValue', $result[0]['value']);

	// Shopsoftware
	$refPage->assign('shopData', _('Shop data') . ' :');

	// Version
	$refPage->assign('versionText', _('Shop-Version') . ' :');
	$refPage->assign('versionValue', VERSION);

	// Errormessages
	db::getInstance()->where('error_done', 0);
	$result = db::getInstance()->get('error');
	$errorList = '';
	$refPage->assign('errorText', _('Errormessages') . ' :');

	if (db::getInstance()->count > 0)
	{
		foreach ($result as $row)
		{
			$length = strpos($row['error_text'], '<br>');
			if ($length > 0)
				$errorList .= substr($row['error_text'], 0, $length) . '<br>';
		}

		if (!empty($errorList))
			$refPage->assign('errorRow', $errorList);
	}
	else
		$refPage->assign('errorRow', _('- none -'));

	// Shipping
	$refPage->assign('shippingText', _('Shipping-Plugins') . ' :');
	$result = db::getInstance()->get('shipping');
	$value = '';

	foreach ($result as $row)
	{
		if ($row['shipping_active'] == 1)
		{
			$value .= $row['shipping_name'] . '<br>';
		}
		else
		{
			$value .= $row['shipping_name'] . ' ' . _('(deactivated)') . '<br>';
		}
	}
	$refPage->assign('shippingValue', $value);

	// Payment
	$refPage->assign('paymentText', _('Payment-Plugins') . ' :');
	$result = db::getInstance()->get('payment');
	$value = '';

	foreach ($result as $row)
	{
		if ($row['payment_active'] == 1)
		{
			$value .= $row['payment_name'] . '<br>';
		}
		else
		{
			$value .= $row['payment_name'] . ' ' . _('(deactivated)') . '<br>';
		}
	}
	$refPage->assign('paymentValue', $value);

	// Display all X-Plugins in a seperate list
	$pluginNames = xPlugin::getPluginNames();
	$xPlugins = '';

	foreach ($pluginNames as $row)
	{
		$xPlugins .= $row['name'] . ' ';

		if ($row['active'] == 0)
		{
			$xPlugins .= _('(Deactive)') . '<br>';
		}
		else
		{
			$xPlugins .= _('(Active)') . '<br>';
		}
	}
	$refPage->assign('xPlugins', $xPlugins);
	$refPage->addtpl('content', '/' . $page . '/' . $subpage . '.tpl.php');
}

?>